package model;

import entity.Employee;
import entity.Orders;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Noi
 */
public class HistoryEmployeeTableModel extends AbstractTableModel {

    private manager.Manager manager;
    private ArrayList<Orders> alOrders;

    public HistoryEmployeeTableModel(manager.Manager manager) {
        this.manager = manager;
        alOrders = new ArrayList<Orders>();
    }

    public void setEmployee(Employee employee) {
        alOrders = this.manager.getOrdersManager().getByEmployeeID(employee.getEmployeeID());
        this.fireTableDataChanged();
    }

    @Override
    public int getRowCount() {
        return this.alOrders.size();
    }

    @Override
    public int getColumnCount() {
        return 4;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        Orders orders = this.alOrders.get(rowIndex);
        SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy");
        switch (columnIndex) {
            case 0:
                return orders.getOrdersID();
            case 1:
                return df.format(orders.getIssueDate());
            case 2:
                return df.format(orders.getDueDate());
            case 3:
                if(orders.isReturned()) return "Yes";
                else return "No";
            default:
                return null;
        }
    }

    @Override
    public String getColumnName(int column) {
        switch(column) {
            case 0:
                return "Orders ID";
            case 1:
                return "Issue Date";
            case 2:
                return "Due Date";
            case 3:
                return "Returned";
            default:
                return null;
        }
    }

    public void removeAllElements() {
        this.alOrders.clear();
    }
    
    public Orders get(int index) {
        return this.alOrders.get(index);
    }
}